// 对下标排序
class Solution {
public:
    vector<string> sortPeople(vector<string>& names, vector<int>& heights) {
        vector<int> index;
        for (int i = 0; i < names.size(); i++) index.push_back(i);
        sort(index.begin(), index.end(), 
            [&heights](int a, int b){ return heights[a] > heights[b]; });
        vector<string> ret;
        for (int i : index)
            ret.push_back(names[i]);
        return ret;
    }
};
    
// 优势洗牌
class Solution {
public:
    vector<int> advantageCount(vector<int>& nums1, vector<int>& nums2) {
        int n = nums1.size();
        sort(nums1.begin(), nums1.end());
        vector<int> index(n);
        for (int i = 0; i < n; i++) index[i] = i;
        sort(index.begin(), index.end(), [&nums2](int a, int b){ 
            return nums2[a] < nums2[b]; 
        });
        vector<int> ret(n);
        int left = 0, right = n - 1;
        for (auto e : nums1)
        {
            if (e > nums2[index[left]]) ret[index[left++]] = e;
            else ret[index[right--]] = e;
        }
        return ret;
    }
};
    